package com.itheima.zuoye.zy2.zuoye2_2;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;

public class MyRunnable implements Runnable {
    //    添加集合{10,5,20,50,100,200,500,800,2,80,300,700};
    ArrayList<Integer> list = new ArrayList<>();

    public MyRunnable() {
        list.add(10);
        list.add(5);
        list.add(20);
        list.add(50);
        list.add(100);
        list.add(200);
        list.add(500);
        list.add(800);
        list.add(2);
        list.add(80);
        list.add(300);
        list.add(700);
    }

    @Override
    public void run() {
        ArrayList list1 = new ArrayList();
        int sum = 0;

        for (int i = 0; i < 6; i++) {
            synchronized (MyRunnable.class) {
                Integer a = prizedraw();
                list1.add(a);
                sum += a;
            }
        }
        System.out.println("在此次抽奖过程中" + Thread.currentThread().getName() + "公产生" + list1.size() + "个奖项分别为" + list1 +
                "最高奖项为" + Collections.max(list1) + "总金额为" + sum);
    }

    public Integer prizedraw() {
        return list.remove(new Random().nextInt(list.size()));

    }


}

